﻿using Autofac.Core;
using CoreProject.DTO;
using CoreProject.IService;
using Microsoft.AspNetCore.Mvc;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace CoreProject.Api.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class PderxqController : ControllerBase
    {
        private readonly IPderxqService _derxqService;
        public PderxqController(IPderxqService derxqService)
        {
            _derxqService = derxqService;
        }
        // GET: api/<PderxqController>
        [HttpGet]
        public async Task<ResultData<List<PderxqDto>>> Get()
        {
            var data = await _derxqService.cha();
            var zz=new List<PderxqDto>();
            foreach (var item in data) { 
                PderxqDto dto = new PderxqDto();
                dto.Pxqid = item.Pxqid;
                dto.Gid = item.GId;
                dto.Price=(float)item.Price;
                dto.Sfpl = item.Sfpl;
                dto.Shu = item.Shu;
                dto.Pbh = item.Pbh;
                dto.Name = item.GIdNavigation.Name;
                dto.zt = item.PbhNavigation.Zt;
                dto.Images = item.GIdNavigation.Images;
                zz.Add(dto);
            }
            ResultData<List<PderxqDto>> result = new ResultData<List<PderxqDto>>();

           
           
            result.state = 200;
            result.code = "1";
            result.msg = "ok";
            result.data = zz;
            return result;
        }

        // GET api/<PderxqController>/5
        [HttpGet("{id}")]
        public string Get(int id)
        {
            return "value";
        }

        // POST api/<PderxqController>
        [HttpPost]
        public void Post([FromBody] string value)
        {
        }

        // PUT api/<PderxqController>/5
        [HttpPut("{id}")]
        public void Put(int id, [FromBody] string value)
        {
        }

        // DELETE api/<PderxqController>/5
        [HttpDelete("{id}")]
        public void Delete(int id)
        {
        }
    }
}
